package com.neuronbit.businessflow.intellij.editor.swing;

import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.util.Objects;

import static java.lang.String.format;

/**
 * The type Mx page.
 */
public class mxPage implements Comparable<mxPage> {

    private final int i;
    private final int j;
    private final Rectangle rectangle;

    /**
     * Instantiates a new Mx page.
     *
     * @param i         the
     * @param j         the j
     * @param rectangle the rectangle
     */
    public mxPage(int i, int j, Rectangle rectangle) {
        this.i = i;
        this.j = j;
        this.rectangle = rectangle;
    }

    /**
     * Gets rectangle.
     *
     * @return the rectangle
     */
    public Rectangle getRectangle() {
        return rectangle;
    }

    /**
     * Gets i.
     *
     * @return the i
     */
    public int getI() {
        return i;
    }

    /**
     * Gets j.
     *
     * @return the j
     */
    public int getJ() {
        return j;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        mxPage mxPage = (mxPage) o;
        return i == mxPage.i && j == mxPage.j;
    }

    @Override
    public int hashCode() {
        return Objects.hash(i, j);
    }

    @Override
    public String toString() {
        return "mxPage{" +
                "i=" + i +
                ", j=" + j +
                format(", rectangle=(x=%s, y=%s, w=%s, h=%s)", rectangle.x, rectangle.y, rectangle.width, rectangle.height) +
                '}';
    }

    @Override
    public int compareTo(@NotNull mxPage o) {
        int i1 = this.i - o.i;

        if (i1 == 0) {
            return this.j - o.j;
        }
        return i1;
    }
}
